import React, { Component } from 'react';
import { index_banner, user_login } from '../../utils/api'
import './Banner.scss'

class Banner extends Component {
    // 挂载期(挂载期的方法会自动执行，而且只执行一次)
    constructor(props) {//这个函数会在组件挂载前就执行，组件并没有显示在页面上
        super(props);
        // console.log('constructor');
        this.state = {
            list: [],
            pic: ''
        }//初始化组件状态
    }
    componentDidMount() {
        index_banner().then((res) => {
            this.setState(
                this.state.list = res.data.list
            )
            this.state.pic = this.state.list[0].pic
            console.log(res.data);
            console.log(this.state.list[0].pic);
        })
    }
    render() {
        return (
            <div className='banner'>
                <img src={this.state.pic} alt="" />
                {/* <img src={this.state.list[0].pic} alt="" /> */}
            </div>
        );
    }

}

export default Banner;